package com.netease.pris.activity.view;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.ViewFlipper;
import com.netease.g.b;
import com.netease.image.c;
import com.netease.pris.activity.PRISActivitySetting;
import com.netease.pris.c.a;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class AdView extends FrameLayout
{
  public static final long a = 300000L;
  private static final String b = "AdViewFlipper";
  private static final int c = 2;
  private static final float d = 40.0F;
  private boolean e = false;
  private boolean f = false;
  private boolean g = false;
  private boolean h = false;
  private boolean i = true;
  private int j = 0;
  private int k = 0;
  private List l;
  private List m;
  private AdView.AdBroadcast n;
  private Context o;
  private ImageView p;
  private ViewFlipper q;
  private final BroadcastReceiver r = new z(this);
  private final int s = 1;
  private final Handler t = new cls_v(this);

  public AdView(Context paramContext)
  {
    super(paramContext);
    a(paramContext);
  }

  public AdView(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    a(paramContext);
  }

  private Bitmap a(Uri paramUri)
  {
    return BitmapFactory.decodeFile(paramUri.getPath());
  }

  private void a(long paramLong)
  {
    a(new y(this), paramLong);
  }

  private void a(Context paramContext)
  {
    this.o = paramContext;
  }

  private void a(List paramList)
  {
    this.m = paramList;
  }

  private void a(List paramList, ImageView paramImageView, int paramInt)
  {
    if ((paramList == null) || (paramList.size() == 0));
    while (true)
    {
      return;
      if (paramInt >= paramList.size())
        paramInt %= paramList.size();
      paramImageView.setImageBitmap(a(((m)paramList.get(paramInt)).a));
      paramImageView.setTag(paramList.get(paramInt));
    }
  }

  private void g()
  {
    this.p.setOnClickListener(new x(this));
  }

  private void h()
  {
    if (d());
    while (true)
    {
      return;
      if (f() > 0)
      {
        SharedPreferences localSharedPreferences = this.o.getSharedPreferences("ad_pref", 0);
        this.j = localSharedPreferences.getInt("key_curpos", 0);
        this.k = localSharedPreferences.getInt("key_curindex", 0);
        a((List)this.l.get(this.j), this.k);
        this.q.setVisibility(0);
        this.p.setVisibility(0);
        continue;
      }
    }
  }

  private List i()
  {
    return this.m;
  }

  private void j()
  {
    boolean bool;
    if ((this.g) && (this.h) && (this.i))
      bool = true;
    while (true)
    {
      List localList;
      Message localMessage;
      if (bool != this.f)
      {
        localList = i();
        if ((!bool) || (localList == null) || (localList.size() <= 0))
          break;
        localMessage = this.t.obtainMessage(1);
        if (this.k < localList.size())
          break label197;
        if ((this.l != null) && (this.l.size() > 0))
        {
          this.j = (1 + this.j);
          if (this.j >= this.l.size())
            this.j %= this.l.size();
          a((List)this.l.get(this.j), 0);
          b.b("AdViewFlipper", "updateRunning:onLoad(mAdList.get(" + this.j + "), 0)");
        }
      }
      return;
      bool = false;
      continue;
      label197: this.t.sendMessageDelayed(localMessage, ((m)localList.get(this.k)).b);
    }
    while (true)
    {
      this.f = bool;
      break;
      this.t.removeMessages(1);
    }
  }

  public void a()
  {
    long l1 = PRISActivitySetting.n(this.o);
    long l2 = System.currentTimeMillis() - l1;
    if (l2 >= 300000L)
      h();
    while (true)
    {
      return;
      a(300000L - l2);
    }
  }

  public void a(bt parambt, long paramLong)
  {
    if (this.n == null)
      this.n = new AdView.AdBroadcast(this.o);
    this.n.a(parambt, paramLong);
  }

  public void a(List paramList, int paramInt)
  {
    StringBuilder localStringBuilder = new StringBuilder().append("onLoad:list.size()=");
    Object localObject;
    if (paramList == null)
    {
      localObject = "null";
      b.b("AdViewFlipper", localObject + " firstIndex=" + paramInt);
      if ((paramList != null) && (paramList.size() != 0))
        break label75;
    }
    while (true)
    {
      return;
      localObject = Integer.valueOf(paramList.size());
      break;
      label75: if (paramInt < 0)
        paramInt = 0;
      if (paramInt >= paramList.size())
        paramInt = -1 + paramList.size();
      this.q.removeAllViews();
      for (int i1 = 0; i1 < 2; i1++)
      {
        ImageView localImageView = new ImageView(this.o);
        localImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        FrameLayout.LayoutParams localLayoutParams = new FrameLayout.LayoutParams(-1, c.a(this.o, 40.0F));
        this.q.addView(localImageView, i1, localLayoutParams);
        a(paramList, localImageView, paramInt + i1);
        localImageView.setOnClickListener(new aa(this));
      }
      Animation localAnimation = AnimationUtils.loadAnimation(this.o, 2130968587);
      localAnimation.setAnimationListener(new u(this));
      this.q.setInAnimation(localAnimation);
      this.q.setOutAnimation(AnimationUtils.loadAnimation(this.o, 2130968588));
      this.e = true;
      this.h = true;
      this.f = false;
      a(paramList);
      this.k = paramInt;
      j();
    }
  }

  public void b()
  {
    this.o = null;
    if (this.n != null)
    {
      this.n.a();
      this.n = null;
    }
    c();
  }

  public void c()
  {
    this.h = false;
    this.e = false;
    this.h = false;
    j();
    if (this.q != null)
    {
      this.q.clearAnimation();
      this.q.removeAllViews();
    }
    if (this.l != null)
    {
      Iterator localIterator = this.l.iterator();
      while (localIterator.hasNext())
        ((List)localIterator.next()).clear();
    }
    this.m = null;
  }

  public boolean d()
  {
    return this.e;
  }

  /** @deprecated */
  public void e()
  {
    monitorenter;
    try
    {
      if (this.n != null)
        this.n.a();
      monitorexit;
      return;
    }
    finally
    {
      localObject = finally;
      monitorexit;
    }
    throw localObject;
  }

  public int f()
  {
    if (this.l == null)
      this.l = new ArrayList();
    this.l.clear();
    for (int i1 = 0; i1 < 10; i1++)
    {
      File localFile = new File(a.a());
      if (!localFile.exists())
        continue;
      File[] arrayOfFile = localFile.listFiles();
      if ((arrayOfFile == null) || (arrayOfFile.length <= 0))
        continue;
      ArrayList localArrayList = new ArrayList();
      localArrayList.clear();
      int i2 = arrayOfFile.length;
      for (int i3 = 0; i3 < i2; i3++)
      {
        m localm = new m();
        localm.a = Uri.fromFile(arrayOfFile[i3]);
        localm.b = (2000 * (i3 + 1) + i1 * 500);
        localArrayList.add(localm);
      }
      this.l.add(localArrayList);
    }
    return this.l.size();
  }

  protected void onAttachedToWindow()
  {
    super.onAttachedToWindow();
    IntentFilter localIntentFilter = new IntentFilter();
    localIntentFilter.addAction("android.intent.action.SCREEN_OFF");
    localIntentFilter.addAction("android.intent.action.USER_PRESENT");
    getContext().registerReceiver(this.r, localIntentFilter);
    g();
    a();
  }

  protected void onDetachedFromWindow()
  {
    super.onDetachedFromWindow();
    this.g = false;
    getContext().unregisterReceiver(this.r);
    j();
    b();
  }

  protected void onWindowVisibilityChanged(int paramInt)
  {
    super.onWindowVisibilityChanged(paramInt);
    if (paramInt == 0);
    for (boolean bool = true; ; bool = false)
    {
      this.g = bool;
      j();
      return;
    }
  }
}

/* Location:           D:\android\hack\dex2jar-0.0.9.8\classes_dex2jar.jar
 * Qualified Name:     com.netease.pris.activity.view.AdView
 * JD-Core Version:    0.6.0
 */